package o;

import com.google.android.exoplayer2.audio.AudioProcessor;
import com.google.android.exoplayer2.audio.AudioProcessor.UnhandledFormatException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;

public final class acu implements AudioProcessor {
    private ByteBuffer ʻ = ˏ;
    private boolean ʼ;
    private int ʽ = -1;
    private int ˊ;
    private int ˊॱ;
    private boolean ˋ;
    private byte[] ˋॱ = anr.ʽ;
    private int ˎ;
    private long ˏॱ;
    private boolean ͺ;
    private int ॱ = -1;
    private ByteBuffer ॱˊ = ˏ;
    private int ॱॱ;
    private int ᐝ;

    public void ˋ(int i, int i2) {
        this.ˊ = i;
        this.ˎ = i2;
    }

    public void ॱॱ() {
        this.ˏॱ = 0;
    }

    public long ˋॱ() {
        return this.ˏॱ;
    }

    public boolean ˋ(int i, int i2, int i3) throws UnhandledFormatException {
        if (i3 != 2) {
            throw new UnhandledFormatException(i, i2, i3);
        }
        boolean z;
        if (this.ˊॱ > 0) {
            this.ˏॱ += (long) (this.ˊॱ / this.ॱॱ);
        }
        this.ॱ = i2;
        this.ʽ = i;
        this.ॱॱ = anr.ˊ(2, i2);
        this.ˋॱ = new byte[(this.ˎ * this.ॱॱ)];
        this.ˊॱ = 0;
        this.ᐝ = this.ˊ * this.ॱॱ;
        boolean z2 = this.ˋ;
        if (this.ˊ == 0 && this.ˎ == 0) {
            z = false;
        } else {
            z = true;
        }
        this.ˋ = z;
        this.ʼ = false;
        if (z2 != this.ˋ) {
            return true;
        }
        return false;
    }

    public boolean ˏ() {
        return this.ˋ;
    }

    public int ˋ() {
        return this.ॱ;
    }

    public int ˊ() {
        return 2;
    }

    public int ˎ() {
        return this.ʽ;
    }

    public void ˎ(ByteBuffer byteBuffer) {
        int position = byteBuffer.position();
        int limit = byteBuffer.limit();
        int i = limit - position;
        if (i != 0) {
            this.ʼ = true;
            int min = Math.min(i, this.ᐝ);
            this.ˏॱ += (long) (min / this.ॱॱ);
            this.ᐝ -= min;
            byteBuffer.position(position + min);
            if (this.ᐝ <= 0) {
                position = i - min;
                i = (this.ˊॱ + position) - this.ˋॱ.length;
                if (this.ʻ.capacity() < i) {
                    this.ʻ = ByteBuffer.allocateDirect(i).order(ByteOrder.nativeOrder());
                } else {
                    this.ʻ.clear();
                }
                min = anr.ॱ(i, 0, this.ˊॱ);
                this.ʻ.put(this.ˋॱ, 0, min);
                i = anr.ॱ(i - min, 0, position);
                byteBuffer.limit(byteBuffer.position() + i);
                this.ʻ.put(byteBuffer);
                byteBuffer.limit(limit);
                position -= i;
                this.ˊॱ -= min;
                System.arraycopy(this.ˋॱ, min, this.ˋॱ, 0, this.ˊॱ);
                byteBuffer.get(this.ˋॱ, this.ˊॱ, position);
                this.ˊॱ = position + this.ˊॱ;
                this.ʻ.flip();
                this.ॱˊ = this.ʻ;
            }
        }
    }

    public void ॱ() {
        this.ͺ = true;
    }

    public ByteBuffer ʽ() {
        ByteBuffer byteBuffer = this.ॱˊ;
        if (this.ͺ && this.ˊॱ > 0 && byteBuffer == ˏ) {
            if (this.ʻ.capacity() < this.ˊॱ) {
                this.ʻ = ByteBuffer.allocateDirect(this.ˊॱ).order(ByteOrder.nativeOrder());
            } else {
                this.ʻ.clear();
            }
            this.ʻ.put(this.ˋॱ, 0, this.ˊॱ);
            this.ˊॱ = 0;
            this.ʻ.flip();
            byteBuffer = this.ʻ;
        }
        this.ॱˊ = ˏ;
        return byteBuffer;
    }

    public boolean ʻ() {
        return this.ͺ && this.ˊॱ == 0 && this.ॱˊ == ˏ;
    }

    public void ʼ() {
        this.ॱˊ = ˏ;
        this.ͺ = false;
        if (this.ʼ) {
            this.ᐝ = 0;
        }
        this.ˊॱ = 0;
    }

    public void ᐝ() {
        ʼ();
        this.ʻ = ˏ;
        this.ॱ = -1;
        this.ʽ = -1;
        this.ˋॱ = anr.ʽ;
    }
}
